package com.jlcindia.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jlcindia.action.classes.ForgetPassowrdAction;
import com.jlcindia.action.classes.LoginAction;
import com.jlcindia.action.classes.RegisterAction;

public class FrontControllerServlet extends HttpServlet {

	LoginAction login = null;
	RegisterAction register=null;
	ForgetPassowrdAction forgetpwd=null;

	
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		System.out.println("-----init()-----");
		super.init(config);
		login = new LoginAction();
		register=new RegisterAction();
		forgetpwd=new ForgetPassowrdAction();
		
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String uri = request.getRequestURI();
		String result="";
		if (uri.endsWith("LoginServlet.jlc")) {
			result=login.verifyUser(request, response);
			System.out.println("result: "+result);
			RequestDispatcher rd=request.getRequestDispatcher(result);
			rd.forward(request, response);
		}
		if (uri.endsWith("RegisterServlet.jlc")) {
			result=register.registerUser(request, response);
			System.out.println("result: "+result);
			RequestDispatcher rd=request.getRequestDispatcher(result);
			rd.forward(request, response);
		}
		if (uri.endsWith("ForgetPassowrdServlet.jlc")) {
			result=forgetpwd.forgetPasswordUser(request, response);
			System.out.println("result: "+result);
			RequestDispatcher rd=request.getRequestDispatcher(result);
			rd.forward(request, response);
		}

	}

}
